import React from 'react'
// import store from "../../store/store"
import {useDispatch,useSelector} from 'react-redux'
import { increment,decrement } from '../../store/slice/countSlice'

export default function Count() {

  const dispatch = useDispatch()
  //点击时获取数据
  const count = useSelector(state=>state.count.count)
  const movieList = useSelector(state=>state.movie.movieList)

  // const { count } = store.getState().count
  // console.log(count);


  const incrementHandle = () => {
    dispatch(increment(10))
  }

  const decreamentHandle = () => {

    dispatch(decrement(13))
  }

  const ifOddDecrementHandle = () => {
    if (count % 2 !== 0) {
      dispatch(increment(3))
    }

  }

  const waitDecrementHandle = () => {

    // console.log(count);

  }

  return (
    <div>
      <h1>我是Count组件 我的值是{count}</h1>
      <h1>我是Count组件 电影列表的个数是{movieList.length}</h1>
      <div>
        <button onClick={incrementHandle}>累加</button>
        <button onClick={decreamentHandle}>累减</button>
        <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
        <button onClick={waitDecrementHandle}>等2s再加1</button>
      </div>

    </div>
  )
}
